//
//  ResultTableViewController.m
//  Surveyer
//
//  Created by Tim on 13-8-16.
//  Copyright (c) 2013年 Tim. All rights reserved.
//

#import "ResultTableViewController.h"
#import "ResultViewCell.h"
#import "ResultRawViewController.h"

@interface ResultTableViewController ()

@end

@implementation ResultTableViewController
@synthesize currentSurvey;
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UINib *nib = [UINib nibWithNibName:@"ResultViewCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"ResultViewCell"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100.0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return currentSurvey.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //if (indexPath.section == 0)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell)
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        cell.textLabel.text = ((SurveyItem *)[currentSurvey.items objectAtIndex:indexPath.row]).title;
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%d",((SurveyItem *)[currentSurvey.items objectAtIndex:indexPath.row]).result.count];
        return cell;
    }
    /*
    else
    {
        ResultViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ResultViewCell"];
        if (!cell)
            cell = [[ResultViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ResultViewCell"];
        cell.currentItem = [currentSurvey.items objectAtIndex:indexPath.row];
        return cell;
    }
     */
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ResultRawViewController *vc = [[ResultRawViewController alloc] initWithStyle:UITableViewStyleGrouped];
    vc.currentItem = [currentSurvey.items objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
